<?php
/**
 * Trainingoffer_Data_Trainingofferdelete
 * delete training offer
 * @author Adrian Stolarski
 */
class Trainingofferadmin_Data_Trainingofferdelete implements Trainingofferadmin_Data_Mainable, 
        Trainingofferadmin_Data_Preparable, Trainingofferadmin_Data_Redirectable{
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    
    /**
     *
     * @var type $database_query
     * database query handler
     */
    public $database_query;
    
    /**
     *
     * @var type $redirect_action
     * redirect action
     */
    public $redirect_action;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * insert new offer
     * @param array $variables
     */
    public function main(array $variables = null) {
        $this->database->connect();
        foreach($variables as $key => $value){
            $variables[$key] = $this->database->escape($value);
        }
        $this->prepare_query($variables);
        $this->database->prepare($this->database_query);
        $this->database->query();
        $this->database->dataOperations();
        $this->redirect_action($variables);
    }
    
    /**
     * prepare_query()
     * prepare database query
     * 
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        $this->database_query = "DELETE FROM training_offer WHERE id=".$variables['id'].";";
    }
    
    /**
     * redirect_action()
     * redirect to offers list
     * @param array $variables
     */
    public function redirect_action(array $variables = null) {
        $this->redirect_action = new Trainingofferadmin_Data_Manageofferslistredirect;
        $this->redirect_action->main($variables);
    }
}
